package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 *  程序启动后,要求用户输入标题和正文,然后将数据保存到article表中
 */
public class Test1 {
    public static void main(String[] args) {
        Article article = InputUtil.getInputObject(new Article(),"发表文章");
        try (
                Connection connection = DBUtil.getConnection();
        ){
            String sql = "INSERT INTO article(title,content) " +
                         "VALUES(?,?)";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,article.getTitle());
            ps.setString(2,article.getContent());
            int num = ps.executeUpdate();
            if(num>0){
                System.out.println("文章发表成功");
            }


        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
